#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define MAX 10

void Swap(int*px, int* py)
{
    int tmp = *px;;
    *px = *py;
    *py = tmp;
}
void Print(int* a, int n)
{
    for (int i = 0; i < n; ++i)
        printf("%d ", a[i]);
    printf("\n");
}
void selectSort(int*a, int n)
{
    int left = 0, right = n;
    while (left < right)
    {
    int mini = left;
    int maxi = right;
        for (int i = left; i <= right; ++i)
        {
            if (a[i] < a[mini])
                mini = i;
            if (a[i] >= a[maxi])
                maxi = i;
        }
        Swap(&a[mini], &a[left]);
        if (maxi == mini)
            maxi = mini;
        Swap(&a[maxi], &a[right]);
        ++left;
        --right;
    }
}

int main()
{
    int a[MAX] = {12, 14,52, 11, 9, 8, 4, 25, 4 , 1};
    //srand(time(0));
    //int i = 0;
    //while(i < MAX)
    //    a[i] = rand() % 30;
    selectSort(a, MAX - 1);
    Print(a, MAX);
    return 0;
}
